/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fontys.time;

import java.util.GregorianCalendar;

/**
 *
 * @author Elton Figaroa
 */
public class Time implements ITime { 
// ********datavelden**************************************
    private int year;
    private int month;    
    private int day;
    private int hours;
    private int minutes;
    private GregorianCalendar gc;

    
// ********constructoren***********************************
        /** * creation of a Time-object with year y, month m, day d, hours h and 
         * minutes m; if the combination of y-m-d refers to a non-existing date 
         * a correct value of this Time-object will be not guaranteed 
         * @param y 
         * @param m 1<=m<=12
         * @param d 1<=d<=31
         * @param h 0<=h<=23
         * @param m 0<=m<=59
         */
         public Time(int y, int m, int d, int h, int min){
             this.year = y;
             this.month = m;
             this.day= d;
             this.hours= h;
             this.minutes= min;
             
             if(m<1||m>12){
                 throw new IllegalArgumentException("Maandgetal moet tussen 1 en 12 zijn");
             }
             
             if(d<1||d>31){
                 throw new IllegalArgumentException("Dag-getal moet tussen 1 en 31 zijn");
             }
             
             if(h<0||h>23){
                 throw new IllegalArgumentException("uren moet tussen 0 en 23 zijn");
             }
             
             if(m<0||m>59){
                 throw new IllegalArgumentException("minuten moet tussen 0 en 31 zijn");
             }
             
             gc = new GregorianCalendar(y, m-1, d, h, min);
             
         }
        
    
       // ********methoden****************************************
     
       
   
    /**
     * 
     * @return the concerning year of this time
     */
        public int getYear(){
        return gc.get(GregorianCalendar.YEAR);
    }
    
    /**
     * 
     * @return the number of the month of this time (1..12)
     */
        public int getMonth(){
        return gc.get(GregorianCalendar.MONTH)+ 1;
        
    }
    
    /**
     * 
     * @return the number of the day in the month of this time (1..31)
     */
        public int getDay(){
        return gc.get(GregorianCalendar.DAY_OF_MONTH);       
    }
    
    /**
     * 
     * @return the number of hours in a day of this time (0..23)
     */
        public int getHours(){
        return gc.get(GregorianCalendar.HOUR_OF_DAY);

    }
    
    /**
     * 
     * @return the number of minutes in a hour of this time (0..59)
     */
        public int getMinutes(){
        return gc.get(GregorianCalendar.MINUTE);

        
    }
    
    /**
     * 
     * @return the concerning day in the week of this time
     */
    
 
        public DayInWeek getDayInWeek(){
       
       DayInWeek resultaat;
       int dag = gc.get(GregorianCalendar.DAY_OF_WEEK);
       
       switch (dag){
           case GregorianCalendar.MONDAY:
               resultaat = DayInWeek.MON;
               break;
           case GregorianCalendar.TUESDAY:
               resultaat = DayInWeek.TUE;
               break;
           case GregorianCalendar.WEDNESDAY:
               resultaat = DayInWeek.WED;
               break;
           case GregorianCalendar.THURSDAY:
               resultaat = DayInWeek.THU;
               break;
           case GregorianCalendar.FRIDAY:
               resultaat = DayInWeek.FRI;
               break;
           case GregorianCalendar.SATURDAY:
               resultaat = DayInWeek.SAT;
               break;
           case GregorianCalendar.SUNDAY:
               resultaat = DayInWeek.SUN;
               break;
           default:
               resultaat = null;
               break;
       }
        
                
       return resultaat;
       
 
    }
    /**"
     * 
     * @param minutes (a negative value is allowed)
     * @return  this time plus minutes
     */
        public Time plus(int minutes){
        Time t = new Time(this.getYear(), this.getMonth(), this.getDay(), this.getHours(), this.getMinutes());
        t.gc.add(GregorianCalendar.MINUTE,minutes);
        return t;
    }
    
    
    /**
     * 
     * @param time
     * @return the difference between this time and [time] expressed in minutes
     */
        public int difference(ITime time) {
        Time temp=(Time)time;
        long tempMs = temp.gc.getTimeInMillis();
        long thisMs = this.gc.getTimeInMillis();
        int ret = 0;
        ret = (int) ((tempMs - thisMs)/60000);
        return ret;
    }

        public int compareTo(ITime t) {
        Time temp=(Time)t;
        return gc.compareTo(temp.gc);
        
    }
}